// Base GameObject class with TypeScript types and modern class syntax
export abstract class GameObject {
  public id: number;
  public ctx: CanvasRenderingContext2D;
  public layer: Layer;
  public components: GameComponent[] = [];

  // Transform properties
  protected _x: number = 0;
  protected _y: number = 0;
  protected _rotation: number = 0;
  protected _scaleX: number = 1;
  protected _scaleY: number = 1;

  constructor() {
    this.id = Date.now();
  }

  // Lifecycle hooks
  abstract ready(): void;
  abstract update(deltaTime: number): void;
  abstract draw(): void;

  // Component management
  addComponent(component: GameComponent): void {
    component.setOwner(this);
    this.components.push(component);
  }

  getComponent<T extends GameComponent>(type: new () => T): T | null {
    return this.components.find(c => c instanceof type) as T || null;
  }

  // Transform methods
  get position(): { x: number; y: number } {
    return { x: this._x, y: this._y };
  }

  set position(pos: { x: number; y: number }) {
    this._x = pos.x;
    this._y = pos.y;
  }
}